package com.sisreq.elementos;

import java.awt.Color;
import java.awt.Component;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

@SuppressWarnings("serial")
public class MyTable extends JTable{
	
	public MyTable(TableModel t){
		this.setModel(t);
		this.setFillsViewportHeight(true);
		this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	
	public boolean isCellEditable(int rowIndex, int colIndex) {
		return false;
	}

	public Component prepareRenderer(TableCellRenderer renderer,
			int row, int column) {
		Component c = super.prepareRenderer(renderer, row, column);
		if (!isRowSelected(row)) {
			c.setBackground(getBackground());
			int modelRow = convertRowIndexToModel(row);
			String type = (String) getModel().getValueAt(modelRow, 8);
			if ("Enviado".equals(type))
				c.setForeground(new Color(255, 85, 0));
			if ("Efetuado".equals(type))
				c.setForeground(new Color(0, 102, 0));
			if ("Cancelado".equals(type))
				c.setForeground(Color.BLACK);
		}

		return c;
	}
	
	@SuppressWarnings({ "unused" })
	private class MyTableModel extends AbstractTableModel implements TableModel{
		
		@SuppressWarnings("rawtypes")
		private Vector colunas;
		@SuppressWarnings("rawtypes")
		private Vector <Vector> dados;
		
		
		@Override
		public int getColumnCount() {
			return colunas.size();
		}

		@Override
		public int getRowCount() {
			return dados.size();
		}

		@Override
		public Object getValueAt(int rowIndex, int columnIndex) {
			return dados.get(rowIndex).get(columnIndex);
		}
		
		
	}
	
	
}
